package com.company.matrix;

public class FlipAndInverImage {
    public int[][] flipAndInvertImage(int[][] image) {
        //invert
        invertImage(image);
        //flip
        flipImage(image);
        return image;
    }
    public void flipArray(int[] source){
        int l=0;
        int r=source.length-1;
        while (l<=r){
            int temp=source[l];
            source[l]=source[r];
            source[r]=temp;
            l++;
            r--;
        }
    }


    private void invertArray(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == 0) {
                arr[i] = 1;
            }else {
                arr[i] = 0;
            }
        }
    }

    public void invertImage(int[][] source){
        for (int i = 0; i < source.length; i++) {
            int[] line = source[i];
            invertArray(line);
        }
    }
    public void flipImage(int[][] source) {
        for (int line = 0; line < source.length; line++) {
            int[] pexLine = source[line];
            flipArray(pexLine);
        }
    }
}
